home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / nturl2path.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  55 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Convert a NT pathname to a file URL and vice versa.'''
  5.  
  6. def url2pathname(url):
  7.     """OS-specific conversion from a relative URL of the 'file' scheme
  8.     to a file system path; not recommended for general use."""
  9.     import string as string
  10.     import urllib as urllib
  11.     url = url.replace(':', '|')
  12.     if '|' not in url:
  13.         if url[:4] == '////':
  14.             url = url[2:]
  15.         components = url.split('/')
  16.         return urllib.unquote('\\'.join(components))
  17.     comp = None.split('|')
  18.     if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
  19.         error = 'Bad URL: ' + url
  20.         raise IOError, error
  21.     drive = comp[0][-1].upper()
  22.     path = drive + ':'
  23.     components = comp[1].split('/')
  24.     for comp in components:
  25.         if comp:
  26.             path = path + '\\' + urllib.unquote(comp)
  27.             continue
  28.     if path.endswith(':') and url.endswith('/'):
  29.         path += '\\'
  30.     return path
  31.  
  32.  
  33. def pathname2url(p):
  34.     """OS-specific conversion from a file system path to a relative URL
  35.     of the 'file' scheme; not recommended for general use."""
  36.     import urllib
  37.     if ':' not in p:
  38.         if p[:2] == '\\\\':
  39.             p = '\\\\' + p
  40.         components = p.split('\\')
  41.         return urllib.quote('/'.join(components))
  42.     comp = None.split(':')
  43.     if len(comp) != 2 or len(comp[0]) > 1:
  44.         error = 'Bad path: ' + p
  45.         raise IOError, error
  46.     drive = urllib.quote(comp[0].upper())
  47.     components = comp[1].split('\\')
  48.     path = '///' + drive + ':'
  49.     for comp in components:
  50.         if comp:
  51.             path = path + '/' + urllib.quote(comp)
  52.             continue
  53.     return path
  54.  
  55.